<template>
  <div class="top">
    <el-card>
      <div class="cldiv">
        <div>
          <el-form :inline="true">
            <el-form-item
              ><el-input placeholder="请输入班级名" v-model="keyword"></el-input
            ></el-form-item>
            <el-form-item
              ><el-button
                type="primary"
                icon="el-icon-search"
                @click="handleQuery"
                >搜 索</el-button
              ></el-form-item
            >
          </el-form>
        </div>
        <div class="add">
          <el-button
            type="success"
            @click="handleAdd"
            icon="el-icon-plus"
            class="cladd"
            >添 加</el-button
          >
        </div>
      </div>
    </el-card>
    <el-card>
      <el-table :data="tbData" border style="width: 100%">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column fixed label="序号" align="center">
          <template slot-scope="scope">{{ scope.$index + 1 }}</template>
        </el-table-column>
        <el-table-column
          label="班级名称"
          align="center"
          property="className"
        ></el-table-column>
        <el-table-column
          label="班级号"
          align="center"
          property="classNum"
        ></el-table-column>
         <el-table-column
          label="专业序号"
          align="center"
          property="specializedNum"
        ></el-table-column>
        <el-table-column
          label="辅导员Id"
          align="center"
          property="counselorId"
        ></el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="150">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="warning"
              @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div>
        <el-dialog :visible.sync="dialogFormVisible">
          <el-form :model="form" :rules="rules" ref="formDemo" class="clfrom">
            <el-form-item
              label="班级名称:"
              :label-width="formLabelWidth"
              prop="className"
              v-show="false"
            >
              <el-input v-model="form.className" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item
              label="班级号:"
              :label-width="formLabelWidth"
              prop="classNum"
            >
              <el-input
                v-model="form.classNum"
                autocomplete="off"
              ></el-input>
            </el-form-item>
             <el-form-item
              label="专业序号:"
              :label-width="formLabelWidth"
              prop="specializedNum"
            >
              <el-input
                v-model="form.specializedNum"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item
              label="辅导员Id:"
              :label-width="formLabelWidth"
              prop="counselorId"
            >
            <el-input
                v-model="form.counselorId"
                autocomplete="off"
              ></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="handleCancel">取 消</el-button>
            <el-button type="primary" @click="handleSave">确 定</el-button>
          </div>
        </el-dialog>
      </div>
      <div>
          <el-pagination
            @size-change ="handlePageSizeChange"
            @current-change ="handlePageIndexChange"
            :current-page="pager.pageIndex"
            :page-size="pager.pageSize"
            :page-count="pager.onThisPage"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pager.count"
            background
        >
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getClassList } from "@/api/classapi";
export default {
  data() {
    return {
      keyword: "",
      tbData: [],
      dialogFormVisible: false,
      formLabelWidth: "120px",
      form: {},
      rules: {},
      pager:{
          pageIndex:1,  //当前页面
          pageSize:10,   // 页面大小
          onThisPage:2,  // 当前页数信息总数
          count:2 // 所以信息总数
        },
    };
  },
  mounted() {
      this.fetchData(this.pager);
  },
  methods: {
    // 拉取后台数据（带分页）
    fetchData() {
      let params = {
        keyword: this.keyword,
        page: this.page,
      };
      getClassList(params).then((res) => {
        console.log(res);
        this.tbData = res.data;
        this.page = res.page;
      });
    },
    handlePageSizeChange(){

    },
    handlePageIndexChange(){

    },
    handleQuery() {
      if (this.keyword == "") {
        this.$message.warning("查询条件不能为空");
        this.keyword = "";
        return;
      }
      console.log("你输入的查询条件:" + this.keyword);
    },
    handleAdd() {
      this.dialogFormVisible = true;
    },
    handleEdit() {
      this.dialogFormVisible = true;
    },
    handleCancel() {
      this.dialogFormVisible = false;
    },
    handleSave() {
      this.dialogFormVisible = false;
    },
  },
};
</script>
<style>
.cldiv {
  display: flex;
  float: left;
}
.cladd {
  margin-top: 1px;
}
.clfenye {
  margin-top: 30px;
  margin-bottom: 10px;
}
.clfrom > .el-form-item > .el-form-item__label {
  font-weight: bolder !important;
  font-size: 18px;
}
</style>
